home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-06-23 | 4.7 KB | 153 lines |
- /*
- * QuickTime for Java SDK Sample Code
-
- Usage subject to restrictions in SDK License Agreement
- * Copyright: © 1996-1999 Apple Computer, Inc.
-
- */
- import java.awt.*;
- import java.awt.event.*;
- import java.io.IOException;
-
- import quicktime.*;
- import quicktime.io.*;
- import quicktime.std.movies.*;
- import quicktime.app.display.QTCanvas;
- import quicktime.app.players.QTPlayer;
- import quicktime.std.*;
- import quicktime.vr.*;
-
- public class MovieCallbacks extends Frame implements Errors {
-
- public static void main (String args[]) {
- try {
- System.out.println ("Open a Multi-node VR Movie...");
- QTSession.open (QTSession.kInitVR);
- //register handler for QTRuntimeExceptions
- QTRuntimeException.registerHandler (new Handler());
-
- MovieCallbacks pm = new MovieCallbacks("QT in Java");
- pm.pack();
- pm.show();
- pm.toFront();
- } catch (QTException e) {
- if (e.errorCode() == userCanceledErr) {
- QTSession.close();
- System.exit(0);
- }
- e.printStackTrace();
- QTSession.close();
- }
- }
-
- MovieCallbacks (String title) throws QTException {
- super (title);
-
- QTFile qtf = QTFile.standardGetFilePreview(QTFile.kStandardQTFileTypes);
-
- OpenMovieFile movieFile = OpenMovieFile.asRead(qtf);
- Movie m = Movie.fromFile (movieFile);
- MovieController mc = new MovieController (m);
- mc.setKeysEnabled (true);
-
- Track t = m.getQTVRTrack (1);
- if (t != null) { //setup VR callbacks
- QTVRInstance vr = new QTVRInstance (t, mc);
- vr.setEnteringNodeProc (new EnteringNode(), 0);
- vr.setLeavingNodeProc (new LeavingNode(), 0);
- vr.setMouseOverHotSpotProc (new HotSpot(), 0);
- Interceptor ip = new Interceptor();
- vr.installInterceptProc (QTVRConstants.kQTVRSetPanAngleSelector, ip, 0);
- vr.installInterceptProc (QTVRConstants.kQTVRSetTiltAngleSelector, ip, 0);
- vr.installInterceptProc (QTVRConstants.kQTVRSetFieldOfViewSelector, ip, 0);
- vr.installInterceptProc (QTVRConstants.kQTVRSetViewCenterSelector, ip, 0);
- vr.installInterceptProc (QTVRConstants.kQTVRTriggerHotSpotSelector, ip, 0);
- vr.installInterceptProc (QTVRConstants.kQTVRGetHotSpotTypeSelector, ip, 0);
- }
-
- // set up movie drawing callback
- m.setDrawingCompleteProc (StdQTConstants.movieDrawingCallWhenChanged, new MovieDrawing());
- // set up action filter
- mc.setActionFilter (new PMFilter(), false); //don't do idle events
-
- QTPlayer myQTPlayer = new QTPlayer (mc);
- QTCanvas myQTCanvas = new QTCanvas();
- add(myQTCanvas);
- myQTCanvas.setClient (myQTPlayer, true);
-
- addWindowListener(new WindowAdapter () {
- public void windowClosing (WindowEvent e) {
- QTSession.close();
- dispose();
- }
-
- public void windowClosed (WindowEvent e) {
- System.exit(0);
- }
- });
- }
-
- static class MovieDrawing implements MovieDrawingComplete {
- public int execute (Movie m) {
- System.out.println ("drawing:" + m);
- return 0;
- }
- }
-
- static class EnteringNode implements QTVREnteringNode {
- public int execute (QTVRInstance vr, int nodeID) {
- System.out.println (vr + ",entering:" + nodeID);
- return 0;
- }
- }
-
- static class LeavingNode implements QTVRLeavingNode {
- public int execute (QTVRInstance vr, int fromNodeID, int toNodeID, boolean[] cancel) {
- System.out.println (vr + ",leaving:" + fromNodeID + ",entering:" + toNodeID);
- // no error and Don't cancel leaving node
- // cancel[0] = true; -> this would cancel leaving the fromNode
- return 0;
- }
- }
-
- static class HotSpot implements QTVRMouseOverHotSpot {
- public int execute (QTVRInstance vr, int hotSpotID, int flags) {
- System.out.println (vr + ",hotSpot:" + hotSpotID + ",flags=" + flags);
- return 0;
- }
- }
-
- static class Interceptor implements QTVRInterceptor {
- public boolean execute (QTVRInstance vr, QTVRInterceptRecord qtvrMsg) {
- System.out.println (vr + "," + qtvrMsg);
- return false; //dont cancel default execution
- }
- }
-
- static class PMFilter extends ActionFilter {
- public boolean execute (MovieController mc, int action) {
- System.out.println (mc + "," + "action:" + action);
- return false;
- }
-
- public boolean execute (MovieController mc, int action, float value) {
- System.out.println (mc + "," + "action:" + action + ",value=" + value);
- return false;
- }
- }
-
- //_________________________ Runtime Error Handling
- static class Handler implements QTRuntimeHandler {
- public void exceptionOccurred (QTRuntimeException e, Object eGenerator, String methodNameIfKnown, boolean unrecoverableFlag) {
- System.out.println (eGenerator + "," + methodNameIfKnown + ",unrecoverable=" + unrecoverableFlag);
- e.printStackTrace();
- throw e; // we don't handle this exception - just print stack trace and throw it
- }
- }
- }
-
-
-
-
-
-